# 类似c的数组
from scipy.cluster.hierarchy import num_obs_linkage


def  demo1() :
    name_list = ['张三', '李四', '王五']
    # 按序号查找
    print(name_list[2])
    #  print(name_list[3]) 访存越界
    # 按值查找
    print(name_list.index('王五'))
    # 修改
    name_list[2] = '赵六'
    print(name_list)
    # 删除
    name_list.remove('赵六')
    print(name_list)
    print(name_list.pop())
    # 添加
    name_list.append('赵六')
    print(name_list)
    # 清空
    name_list.clear()
    print(name_list)

def  demo2() :
    num_list  = [1,5,3,10,5,3,7,2,9,4]
    #  排序
    num_list.sort()
    print(num_list)
    num_list.sort(reverse = True)
    print(num_list)
    num_list.reverse() # 反转
    print(num_list)
    # 统计
    print(num_list.count(5))

def demo3() :
    name_list = [5,4,3,2,5,2]
    l = len(name_list)
    # 遍历
    for i in range(l):
        if name_list[i] == 5:
            del name_list[i] # 错误，每次del列表的长度会变短，而for不知道会访存越界
    print(name_list)

def demo4():
    a = [x for x in range(10)] # 列表生成式
    print(a)
    b = [j for i in range(10) for j in range(i)]
    print(b)
    c = [[col*row for col in range(5)]for row in range(5)]
    print(c)

if __name__ == '__main__':
    demo1()
    print("-" * 20)
    demo2()
    # demo3()
    demo4()
